
import { request } from '@/utils/request';


import { BaseModel } from '@/api/common/baseModel'

/**
 * 商品
 */
export interface Model extends BaseModel {
  /**
   * 图片
   */
  picUrl: string

  /**
   * 描述
   */
  description?: string
}

// 更新商品
export const update = (data: any, imgs: string[]) => {
  let url = '/userCenter/trade/goods/goods/update.json?'

  if (imgs && imgs.length > 0) {
    url = url + `imgs=` + encodeURIComponent?.(JSON?.stringify?.(imgs))
  }

  return request.put({ url: url, data })
}

// 删除商品
export const del = (id: string) => {
  return request.delete({ url: `/staff/web/userCenter/trade/goods/goods/del.json?id=${id}` })
}

// 获得商品
export const getById = (id: string) => {
  return request.get({ url: `/staff/web/userCenter/trade/goods/goods/getById.json?id=${id}` })
}

// 获得商品列表
export const getPage = (params: any) => {
  return request.get({
    url: '/staff/web/userCenter/trade/goods/goods/page.json',
    params
  })
}

// 上架
export const onsale = (id: string) => {
  return request.get({ url: `/staff/web/userCenter/trade/goods/goods/onsale.json?id=${id}` })
}

// 下架
export const instock = (id: string) => {
  return request.get({ url: `/staff/web/userCenter/trade/goods/goods/instock.json?id=${id}` })
}
